package com.enjoy.xbase.xui.load;

import android.view.View;

import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.enjoy.xbase.R;


public class DefaultLoad extends BaseLoad {

    protected int getLoadLayoutId() {
        return R.layout.xbase_lv_default_load;
    }

    @Override
    protected int getFailLayoutId() {
        return R.layout.xbase_lv_default_faill;
    }

    @Override
    protected int getEmptyLayoutId() {
        return R.layout.xbase_lv_default_empty;
    }

    @Override
    protected int getLoadingLayoutId() {
        return R.layout.xbase_lv_default_loading;
    }

    @Override
    protected void onLoadShow(View loadView, boolean first, Object param) {

    }

    @Override
    protected void onLoadHide(View loadView) {

    }

    @Override
    protected void onFailShow(View failView, boolean first, Object param) {
        if (first) {
            View btnRefresh = failView.findViewById(R.id.load_btn_refresh);
            if (btnRefresh != null) {
                btnRefresh.setOnClickListener(v -> {
                    if (loadView != null && loadView.loadRefresh != null) {
                        loadView.showLoad();
                        loadView.loadRefresh.onRefresh();
                    }
                });
            }
        }
    }

    @Override
    protected void onFailHide(View failView) {

    }

    @Override
    protected void onEmptyShow(View emptyView, boolean first, Object param) {
        if (first) {
            View refreshLayout = emptyView.findViewById(R.id.load_srl_refresh);
            if (refreshLayout != null && refreshLayout instanceof SwipeRefreshLayout) {
                ((SwipeRefreshLayout) refreshLayout).setOnRefreshListener(() -> {
                    ((SwipeRefreshLayout) refreshLayout).setRefreshing(false);
                    if (loadView != null && loadView.loadRefresh != null) {
                        loadView.showLoad();
                        loadView.loadRefresh.onRefresh();
                    }
                });
            }
        }
    }

    @Override
    protected void onEmptyHide(View emptyView) {

    }

    @Override
    protected void onLoadingShow(View loadingView, boolean first, Object param) {

    }

    @Override
    protected void onLoadingHide(View loadingView) {

    }
}
